package com.hlkj.warboot.module_laboratory.controller;

import com.hlkj.warboot.configurer.util.*;
import com.hlkj.warboot.module_sys.entity.AdminEntity;
import com.hlkj.warboot.module_sys.service.AdminService;
import com.hlkj.warboot.module_laboratory.configurer.util.JdkProxyUtil;
import com.hlkj.warboot.module_laboratory.service.LaboratoryService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: TODO 测试模块
 * @Author: lixing
 * @Date: 2020/2/16 16:44
 */
@RestController
@RequestMapping("laboratory")
public class LaboratoryComtroller {

    @RequestMapping("aop1")
    public Object aop1(HttpServletRequest request, AdminEntity entity) {
        System.out.println("");
        return ResponseUtil.success(entity);
    }

    @RequestMapping("aop2")
    public Object aop2(HttpServletRequest request) {
        return ResponseUtil.success("Hello2");
    }

    @Resource()
    private LaboratoryService laboratoryService;

    @RequestMapping("staticProxy")
    public Object staticProxy() {
        LaboratoryService proxy = (LaboratoryService) new JdkProxyUtil(laboratoryService).getProxy();
        proxy.add();
        return ResponseUtil.success();
    }

    @Resource
    private AdminService adminService;

    @RequestMapping("transaction")
    @Transactional()
    public Object transaction() {
        AdminEntity adminEntity = new AdminEntity();
        adminEntity.setAccount("a");
        adminEntity.setPass("a");
        boolean flag = adminService.save(adminEntity);
        System.out.println(0 / 0);
        return ResponseUtil.success();
    }

    // laboratory/redis
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @RequestMapping("redis")
    public Object redis() {
        return ResponseUtil.success();
    }

}
